package com.cc.gulimall.search.controller;


import com.cc.gulimall.search.service.MallService;
import com.cc.gulimall.search.vo.SearchParam;
import com.cc.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>Title: SearchController</p>
 * Description：
 * date：2020/6/12 21:46
 */

@Controller
public class SearchController {

    @Autowired
    private MallService masllService;

/*    @GetMapping("/list.html")
    public String listPage() {
        return "list";
    }*/

    /*让springMVC自动将查询参数封装到我们准备好的类SearchParam中*/
    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request) {

        // 获取路径原生的查询属性
        searchParam.set_queryString(request.getQueryString());
        // ES中检索到的结果 传递给页面
        SearchResult result = masllService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }
}
